home *** CD-ROM | disk | FTP | other *** search
- /*_ dos.h Modified by: Walter Bright */
- /* Copyright (C) 1985-1991 by Walter Bright */
- /* All rights reserved */
- /* Written by Walter Bright */
- /* $Revision: 1.10 $ */
-
- /* DOS and IBM PC specific declarations */
-
- #ifndef __DOS_H
- #define __DOS_H 1
-
- #if __cplusplus
- extern "C" {
- #endif
-
- #ifdef __STDC__
- #define __CDECL
- #define __STDCALL
- #else
- #define __CDECL __cdecl
- #define __STDCALL __stdcall
- #endif
-
- #if __OS2__ && __INTSIZE == 4
- #define __CLIB __STDCALL
- #else
- #define __CLIB __CDECL
- #endif
-
- #if !(M_XENIX || M_UNIX)
- #pragma pack(1) /* no alignment for DOS structs */
- #endif
-
- typedef unsigned size_t;
-
- #if DOS386
- /* Valid for both Pharlap and x386. */
- extern unsigned short _x386_zero_base_selector;
-
- /* The following is actually only for X386, not Pharlap. */
- /***************
- Absolute address is given. Selector is returned in dx, offset in eax. A
- selector is normally allocated so the offset will normally be zero. If all
- selectors are being used, the offset is returned in eax with
- _x386_zero_base_selector in dx. This should provide working long pointers to
- most applications even if we have insufficient selectors. Return of zero in
- eax indicates allocation of a selector unless the requested base was zero in
- which case it is ambiguous. Nonzero indicates all selectors have been
- allocated and _x386_zero_base_selector is in dx, requested absolute address
- is in eax. In all cases the descriptor has a 4 gbyte limit.
- ****************/
- extern void __far *(*_x386_mk_protected_ptr)(unsigned long abs_address);
-
- /***************
- Pass a far pointer. Offset portion of pointer is ignored, selector is
- examined to see if it matches pointers previously allocated. If the selector
- is indeed a user definable selector then it is deactivated and a 0 is
- returned. Any attempt to use the selector after it has been freed will
- result in a general protection fault.
-
- If the pointer does not contain a selector created through a call to
- mk_protected_ptr then it returns a -1 with no action taken. This also
- happens if mk_protected_ptr returns nonzero in eax and an attempt is made to
- free the associated selector.
- ****************/
- extern int (*_x386_free_protected_ptr)(void __far *);
-
- /***************
- Function is called with a far pointer. It determines the absolute address
- of that pointer and returns the address in eax.
- ****************/
- extern unsigned long(*_x386_get_abs_address)(void __far *ptr);
-
- /***************
- Function returns the largest contiguous block available via calls to malloc
- or calloc
- ****************/
- extern unsigned int (_x386_coreleft)(void);
-
- /***************
- Function allows access to specific physical addresses in memory.
- The mapped region must be completely above or below the 1M
- boundary. If there is insufficient memory or the DPMI host
- refuses the map, the function returns -1. The return value is
- a near pointer that can be used to access the requested address.
- ****************/
- extern void* (_x386_map_physical_address)(void* abs_addr, unsigned size);
-
- #endif
-
- #ifndef __NT__
-
- /* Register structure required for functions int86() and intdos() */
-
- #if __INTSIZE == 4
-
- #pragma pack(1)
- struct _DWORDREGS
- { unsigned eax,ebx,ecx,edx,esi,edi,cflag,flags;
- };
- #define DWORDREGS _DWORDREGS
-
- struct _WORDREGS
- { unsigned short ax,eaxmsw,bx,ebxmsw,cx,ecxmsw,dx,edxmsw,
- si,esimsw,di,edimsw;
- unsigned cflag,flags;
- };
- #define WORDREGS _WORDREGS
-
- struct _BYTEREGS
- { unsigned char al,ah,ax2,ax3,bl,bh,bx2,bx3,
- cl,ch,cx2,cx3,dl,dh,dx2,dx3;
- };
- #define BYTEREGS _BYTEREGS
-
- union _REGS { struct _DWORDREGS e; struct _WORDREGS x; struct _BYTEREGS h; };
- #define REGS _REGS
-
- struct _SREGS { unsigned short es,cs,ss,ds,fs,gs; };
- #define SREGS _SREGS
-
- #pragma pack()
- #else
-
- #pragma pack(1)
- struct WORDREGS { unsigned ax,bx,cx,dx,si,di,cflag,flags; };
- struct BYTEREGS {unsigned char al,ah,bl,bh,cl,ch,dl,dh; };
- union REGS { struct WORDREGS x; struct BYTEREGS h; };
- struct SREGS { unsigned es,cs,ss,ds; };
- #pragma pack()
- #define _REGS REGS
- #define _SREGS SREGS
- #define _WORDREGS WORDREGS
- #define _BYTEREGS BYTEREGS
-
- #endif
-
-
- #define disable() __emit__((char)(0xFA))
- #define _disable() __emit__((char)(0xFA))
- #define enable() __emit__((char)(0xFB))
- #define _enable() __emit__((char)(0xFB))
- #define geninterrupt(intr) __int__(intr)
-
-
- int __cdecl int86(int,union REGS *,union REGS *);
- int __cdecl int86x(int,union REGS *,union REGS *,struct SREGS *);
- int __cdecl intdos(union REGS *,union REGS *);
- int __cdecl intdosx(union REGS *,union REGS *,struct SREGS *);
- void __CLIB segread(struct SREGS *);
- #define _int86 int86
- #define _int86x int86x
- #define _intdos intdos
- #define _intdosx intdosx
- #define _segread segread
-
- #if DOS386
- int __cdecl int86_real(int,union REGS *,union REGS *);
- int __cdecl int86x_real(int,union REGS *,union REGS *,struct SREGS *);
- #endif
-
- #endif /* !__NT__ */
-
- #if (M_UNIX || M_XENIX)
-
- /***************
- The _vt_ functions help support the use of virtural terminals. See SCREEN(HW)
- for the basics of the ioctl()'s which are hidden by this set of functions.
- Use _vt_add() to add functions to be called at time when requests are made
- to switch screens. Your function will be passed either VT_RELDISP or
- VT_ACTIVATE to identify which action is being taken. If you do not wish to
- release the screen return VT_FALSE for relsig (VT_TRUE if you are ready to
- release it). The return value for acqsig is ignored.
-
- You may add as many functions to be notified as you wish -- the only memory
- constraints are governed by malloc(). Remove functions with _vt_remove.
-
- If you wish to switch to another screen use _vt_activate(). Screen numbers
- are normally 1 -> 12. To find your screen number use _vt_get_num().
- ****************/
-
- /***************
- ioctls supported by the VT
- ****************/
- #define VTIOC ('v' << 8)
- #define VT_OPENQRY (VTIOC | 1)
- #define VT_SETMODE (VTIOC | 2)
- #define VT_GETMODE (VTIOC | 3)
- #define VT_RELDISP (VTIOC | 4)
- #define VT_ACTIVATE (VTIOC | 5)
-
- /***************
- Modes of VT_RELDISP
- ****************/
- #define VT_FALSE 0 /* user will not release display */
- #define VT_TRUE 1 /* user releases display */
- #define VT_ACKACQ 2 /* user acknowleges the acquire signal */
-
- /***************
- Modes of struct vt_mode.mode
- ****************/
- #define VT_AUTO 0 /* this vt switching is automatic */
- #define VT_PROCESS 1 /* this vt switching controlled by a process */
-
- struct vt_mode {char mode, waitv; short relsig, acqsig, frsig;};
-
- typedef int (*_vt_sig_func_t)(int);
-
- /***************
- Return the mode the VT handler is in.
- ****************/
- void _vt_get_mode(struct vt_mode *p);
-
- /***************
- Set the new mode to use with this VT. Return -1 if failure.
- ****************/
- int _vt_set_mode(struct vt_mode *p);
-
- /***************
- Get this processes VT screen number.
- Return -1 if failure or screen number if successful.
- ****************/
- int _vt_get_num(void);
-
- /***************
- Set this VT to be the active one. Return -1 if failure.
- ****************/
- int _vt_activate(int vt_num);
-
- /***************
- Adds a another function to the list to be notified in the event of a
- release/acquire request. Returns -1 if failed.
- ****************/
- int _vt_add(_vt_sig_func_t func);
-
- /***************
- Remove this function from the list of functions to be notified in the event
- of a release/acquire request. Returns -1 if failure to remove it.
- ****************/
- int _vt_remove(_vt_sig_func_t func);
-
-
- #include <sys/stat.h>
-
- struct FIND /* struct used by findfirst() and findnext() */
- {
- struct stat stat;
- unsigned short attribute;/* attribute found (FA_XXXX) */
- unsigned short time,date;/* file's time and date */
- unsigned long size; /* file's size */
- char name[16]; /* filename followed by 0 byte */
- };
-
- /* Directory entry attributes */
- /* Use S_XXXX bit masks in sys/stat.h. */
-
- #define FA_NORMAL 0x00
- #define FA_DIREC S_IFDIR
-
- #else /* !M_UNIX */
-
- #pragma pack(1)
- struct FIND /* struct used by findfirst() and findnext() */
- { char reserved[21]; /* reserved by DOS */
- char attribute; /* attribute found (FA_XXXX) */
- unsigned short time,date; /* file's time and date */
- unsigned long size; /* file's size */
- char name[13]; /* filename followed by 0 byte */
- };
-
- struct find_t /* used by _dos_findfirst() and _dos_findnext() */
- { char reserved[21]; /* reserved by DOS */
- char attrib; /* attribute found (FA_XXXX) */
- unsigned short wr_time,wr_date; /* file's last write */
- unsigned long size; /* file's size */
- char name[13]; /* filename followed by 0 byte */
- };
-
- #define _find_t find_t
- #pragma pack()
-
- /* Directory entry attributes */
- #define FA_NORMAL 0x00
- #define FA_RDONLY 0x01
- #define FA_HIDDEN 0x02
- #define FA_SYSTEM 0x04
- #define FA_LABEL 0x08
- #define FA_DIREC 0x10
- #define FA_ARCH 0x20
-
- #define _A_NORMAL 0x00
- #define _A_RDONLY 0x01
- #define _A_HIDDEN 0x02
- #define _A_SYSTEM 0x04
- #define _A_VOLID 0x08
- #define _A_SUBDIR 0x10
- #define _A_ARCH 0x20
-
- #endif
-
- struct FIND * __CLIB findfirst(const char *,int),* __CLIB findnext(void);
-
- #if MSDOS || _WINDOWS
- unsigned __CLIB _dos_findfirst(char *, unsigned, struct find_t *);
- int __CLIB _dos_findnext(struct find_t *);
- #endif
-
- #ifndef __NT__
- /***************************
- * Define macros to get at the segment and offset of a far pointer.
- */
-
- #define _FP_OFF(fp) (*((unsigned __far *)&(fp)))
- #define FP_OFF _FP_OFF
-
- #if __INTSIZE == 4
- extern unsigned __CLIB FP_SEG(void __far *);
- #else
- #define _FP_SEG(fp) (*((unsigned __far *)&(fp)+1))
- #define FP_SEG _FP_SEG
- #endif
-
-
- /* Generate a far pointer from a segment and an offset */
- #if __INTSIZE == 4
- extern void __far * __CLIB MK_FP(unsigned short,unsigned);
- #define MK_FP(seg,offset) MK_FP((seg),(unsigned)(offset))
- #else
- #define MK_FP(seg,offset) \
- ((void __far *)(((unsigned long)(seg)<<16) | (unsigned)(offset)))
- #endif
- #endif
-
-
- /***********************************
- * Far storage allocation functions
- */
-
- #if __INTSIZE == 2
- void __far * __cdecl farmalloc(unsigned long size);
- void __far * __cdecl farcalloc(unsigned long numelems,unsigned long elemsize);
- void __far * __cdecl farrealloc(void __far *oldptr,unsigned long newsize);
- int __cdecl farfree(void __far *ptr);
- unsigned long __cdecl farcoreleft(void);
- #endif
-
- /* structure for dos_exterr */
-
- #pragma pack(1)
- struct DOSERROR
- {
- int exterror; /* extended error code */
- char eclass; /* error class */
- char action; /* recommended action */
- char locus; /* error locus */
- };
- #define _DOSERROR DOSERROR
-
- /* structure for country dependent information */
- struct COUNTRY {
- short co_date;
- char co_curr[5];
- char co_thsep[2];
- char co_desep[2];
- char co_dtsep[2];
- char co_tmsep[2];
- char co_currstyle;
- char co_digits;
- char co_time;
- long co_case;
- char co_dasep[2];
- char co_fill[10];
- };
-
- /* structure for dos_getdiskfree */
- struct diskfree_t {
- unsigned total_clusters;
- unsigned avail_clusters;
- unsigned sectors_per_cluster;
- unsigned bytes_per_sector;
- };
- #define _diskfree_t diskfree_t
-
- /* structure for dos_setdate/dos_getdate */
-
- struct dos_date_t
- {
- char day;
- char month;
- short year;
- char dayofweek;
- };
- #define _dosdate_t dos_date_t
-
- /* struct for getfat & getfatd */
-
- struct _fatinfo
- {
- char fi_sclus;
- char fi_fatid;
- unsigned fi_nclus;
- int fi_bysec;
- };
- #define fatinfo _fatinfo
-
-
- /* structures for dos_settime/dos_gettime */
-
- struct dos_time_t
- {
- char hour;
- char minute;
- char second;
- char hsecond;
- };
- #define _dostime_t dos_time_t
-
- struct time
- {
- unsigned char ti_min;
- unsigned char ti_hour;
- unsigned char ti_hund;
- unsigned char ti_sec;
- };
-
- struct date
- {
- int da_year;
- char da_day;
- char da_mon;
- };
-
- struct fcb
- {
- char fcb_drive;
- char fcb_name[8];
- char fcb_ext[3];
- short fcb_curblk;
- short fcb_filesize;
- short fcb_date;
- char fcb_resv[10];
- char fcb_crrec;
- long fcb_random;
- };
-
- #pragma pack()
-
- /* DOS specific functions: */
-
- #ifndef __NT__
-
- int __CLIB dos_creat(char *,int);
- int __CLIB _dos_creat(char *,int, int *);
- int __CLIB _dos_creatnew(char *,int , int *);
- void __CLIB dos_set_verify(int);
- void __CLIB dos_set_ctrl_break(int);
- int __CLIB dos_get_verify(void);
- int __CLIB dos_get_ctrl_break(void);
- unsigned __CLIB _dos_open(const char *, unsigned,int *);
- int __CLIB dos_abs_disk_read(int,unsigned int,int,void *);
- int __CLIB dos_abs_disk_write(int,unsigned int,int,const char *);
- #define absread(drive,nsects,lsects,buffer) dos_abs_disk_read(drive,nsects,lsects,buffer)
- #define abswrite(drive,nsects,lsects,buffer) dos_abs_disk_write(drive,nsects,lsects,buffer)
- void __CLIB ctrlbrk(int (*FarPtr)());
- /*static void __CLIB interrupt far CtrlBrkHandler();*/
- int __CLIB getcbrk(void);
- int __CLIB setcbrk(int value);
-
- #endif
-
- int __CLIB getcurdir(int drive,char *dir);
- char * __CLIB _getdcwd(int drive,char *Pbuf,int PbufLen);
- void __CLIB getfat(unsigned char disk, struct fatinfo *fat);
- void __CLIB getfatd(struct fatinfo *fat);
- int __CLIB getverify(void);
- void __CLIB setverify(int value);
- char __far * __CLIB getdta(void);
- void __CLIB setdta(char __far *dta);
- unsigned __CLIB getpsp(void);
- int __CLIB setblock(unsigned segment, unsigned size);
- void __CLIB gettime(struct time *timePtr);
- void __CLIB getdate(struct date *datePtr);
- char * __CLIB parsfnm(const char *cmdline, struct fcb *fcb, int opt);
-
-
- int __CLIB dos_close(int);
- unsigned __CLIB _dos_close(int);
- unsigned __CLIB _dos_commit(int);
- unsigned __CLIB _dos_read(int, void *,unsigned,unsigned *);
- unsigned __CLIB _dos_write(int, const void *,unsigned,unsigned *);
- int __CLIB dos_exterr(struct DOSERROR *);
- int __CLIB dosexterr(struct DOSERROR *);
- #define _dosexterr(dosstruct) dos_exterr(dosstruct)
- #define _dos_close(fd) dos_close(fd)
-
- struct COUNTRY __CLIB country( int , struct COUNTRY *);
-
- int __CLIB setdisk(int);
- int __CLIB getdisk(void);
- long __CLIB dos_getdiskfreespace(int);
- unsigned __CLIB _dos_getdiskfree(unsigned, struct diskfree_t *);
- void __CLIB dos_setdrive(unsigned, unsigned *);
- void __CLIB dos_getdrive(unsigned *);
- unsigned __CLIB dos_setftime(int, unsigned, unsigned);
- unsigned __CLIB dos_getftime(int, unsigned *, unsigned *);
- unsigned __CLIB dos_setfileattr(const char *, unsigned);
- unsigned __CLIB dos_getfileattr(const char *, unsigned *);
- unsigned __CLIB dos_setdate(const struct dos_date_t *);
- void __CLIB dos_getdate(struct dos_date_t *);
- int __CLIB _dos_sethandlecount(unsigned);
- unsigned __CLIB dos_settime(const struct dos_time_t *);
- void __CLIB dos_gettime(struct dos_time_t *);
- #if __INTSIZE == 2
- unsigned _dos_allocmem(unsigned int,unsigned int *);
- int allocmem(unsigned int,unsigned int *);
- unsigned _dos_freemem(unsigned);
- int freemem(unsigned);
- #endif
-
- #define _dos_getdate dos_getdate
- #define _dos_getdrive dos_getdrive
- #define _dos_getfileattr dos_getfileattr
- #define _dos_getftime dos_getftime
- #define _dos_gettime dos_gettime
- #define _dos_setdate dos_setdate
- #define _dos_setdrive dos_setdrive
- #define _dos_setfileattr dos_setfileattr
- #define _dos_setftime dos_setftime
- #define _dos_settime dos_settime
-
- /* For inline code generation for inp(), inpw(), outp() and outpw() functions */
- unsigned char __CLIB _inline_inp(unsigned);
- int __CLIB _inline_inpw(unsigned);
- unsigned char __CLIB _inline_outp(unsigned,char);
- int __CLIB _inline_outpw(unsigned,unsigned);
-
- #define inp(x) _inline_inp(x)
- #define inpw(x) _inline_inpw(x)
- #define outp(x,y) _inline_outp(x,y)
- #define outpw(x,y) _inline_outpw(x,y)
- #define _outp(x,y) _inline_outp(x,y)
- #define _outpw(x,y) _inline_outpw(x,y)
- #define _inp(x) _inline_inp(x)
- #define _inpw(x) _inline_inpw(x)
-
- #if __INTSIZE == 4
- long __CLIB inpl(unsigned);
- long __CLIB outpl(unsigned,unsigned long);
- #endif
-
- size_t __CLIB _chkstack(void);
-
- #ifndef __NT__
- void __cdecl peekbytes(unsigned,unsigned,void *,size_t);
- void __cdecl pokebytes(unsigned,unsigned,const void *,size_t);
- #if __cplusplus
- void inline __cdecl poke(unsigned segm, unsigned offs, int value)
- {
- *((int far *) MK_FP(segm, offs)) = value;
- }
-
- int inline __cdecl peek(unsigned segm, unsigned offs)
- {
- return *((int far *) MK_FP(segm, offs));
- }
- void inline __cdecl pokeb(unsigned segm, unsigned offs, char value)
- {
- *((char far *) MK_FP(segm, offs)) = value;
- }
-
- char inline __cdecl peekb(unsigned segm, unsigned offs)
- {
- return *((char far *) MK_FP(segm, offs));
- }
-
- #else
- #define peek(segm, offs) (*((int far *) MK_FP((segm), (offs))))
- #define peekb(segm, offs) (*((char far *) MK_FP((segm), (offs))))
- #define poke(segm, offs, value) (*((int far *) MK_FP((segm), (offs))) = (int)(value))
- #define pokeb(segm, offs, value) (*((char far *) MK_FP((segm), (offs))) = (char)(value))
- #endif
-
-
- int __cdecl bdos(int dosfunc, unsigned int dosdx, unsigned int dosal);
- #define _bdos bdos
- int __cdecl bdosptr(int, void *, unsigned);
- int __cdecl bdosx(char,void *,char);
-
- /* From parall.asm */
- unsigned __CLIB dos_alloc(unsigned);
- unsigned __CLIB dos_calloc(unsigned);
- int __CLIB dos_free(unsigned);
- void __CLIB _copy(unsigned,unsigned,unsigned);
- unsigned long __CLIB dos_avail(void);
- unsigned __CLIB dos_setblock(unsigned,unsigned);
- unsigned __CLIB _dos_setblock(unsigned,unsigned,unsigned *);
-
-
- #endif
-
- /* From response.c */
- int __pascal response_expand(int *,char ***);
-
- int __CLIB cputype(void);
-
- /* Use this macro if you wish to cause wildcard expansion */
- #if !(M_UNIX || M_XENIX)
- #define WILDCARDS extern int __cdecl __wildcard; int *__wild = &__wildcard;
- #else
- #define WILDCARDS
- #endif
-
- /* Executable type */
- #define EXE_DOS 1 /* MSDOS */
- #define EXE_DOS16RM 2 /* Rational 286 DOS Extender */
- #define EXE_ZPM 4 /* ZPM 286 DOS Extender */
- #define EXE_PHAR386 8 /* Pharlap 386 DOS Extender */
- #define EXE_DOSX 0x10 /* DOSX 386 DOS Extender */
- #define EXE_WINDOWS 0x20 /* Windows 3 */
- #define EXE_OS2 0x40 /* OS/2 1.x */
- #define EXE_SCOUNIX 0x80 /* SCO Unix */
- #define EXE_OS2_2 0x100 /* OS/2 2.0 */
- #define EXE_WINDOWSNT 0x200 /* Windows NT */
-
- extern unsigned short __cdecl _exe_type; /* EXE_XXXX */
-
- #if !(M_UNIX || M_XENIX)
- #pragma pack()
- #endif
-
- #ifdef _WINDOWS
- extern void __far __pascal DOS3CALL(void);
- #define int21h __asm call DOS3CALL
- #else
- #define int21h __asm int 21h
- #endif
-
- #if __cplusplus
- }
- #endif
-
- #endif /* __DOS_H */
-